package treemap01;

import java.util.Comparator;
import java.util.TreeMap;

public class TreeMapDemo02 {
    public static void main(String[] args) {
        TreeMap<Student, String> students = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getScore()-o1.getScore();
            }
        });

        Student s1 = new Student("小红", 85);
        Student s2= new Student("小白", 95);
        Student s3 = new Student("小明", 60);

        students.put(s1, s1.getName());
        students.put(s2, s2.getName());
        students.put(s3, s3.getName());

        //System.out.println(students);
        for (Student key : students.keySet()) {
            System.out.println(key.getName() + "=" + key.getScore());
        }
    }
}
